package cl.tieba.resource;

import static tieba.core.utils.ReturnType.success;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import tieba.core.entity.TieBar;
import tieba.core.entity.TiebaUser;
import tieba.core.utils.TBUtils;

import com.jayway.restassured.response.Cookie;
import com.jayway.restassured.response.Cookie.Builder;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

@Path("core")
@Api("核心")
@Produces(MediaType.APPLICATION_JSON)
public class CoreResource {

	@POST
	@ApiOperation(response = TiebaUser.class, value = "获取Cookie")
	@Path("/login")
	public Response getCookie(@ApiParam("贴吧用户对象") TiebaUser user) {
		return success(TBUtils.login(user));
	}

	@POST
	@ApiOperation(response = TieBar.class, value = "获取喜欢的吧列表")
	@Path("/like")
	public Response getLikes(@ApiParam("贴吧用户对象") TiebaUser user) {
		TiebaUser tu = TBUtils.login(user);
		String bduss = null;
		if (tu.getBDUSS() != null && !"".equals(tu.getBDUSS()))
			bduss = tu.getBDUSS();
		return success(TBUtils.getClientLikes(bduss));
	}

	@GET
	@ApiOperation(response = TieBar.class, value = "获取喜欢的吧列表")
	@Path("/like/{cookie}")
	public Response getLikes(
			@ApiParam("BDUSS Cookie字符串") @PathParam("cookie") String cookie) {
		Cookie bduss = new Builder("BDUSS", cookie).build();
		return success(TBUtils.getLikes(bduss));
	}
}
